/*
* @Author: Marte
* @Date:   2019-06-27 22:33:07
* @Last Modified by:   Marte
* @Last Modified time: 2019-06-30 22:38:39
*/

'use strict';


let log = require('./color_out.js');

let fs = require('fs');

let index = 0;

let out_arr = [

    '\n请输入服务号 appID: ',
    '\n请输入服务号 appsecret: '

];

let in_arr = [];

log('green','欢迎使用数据库初始化向导');

//log('green',out_arr[index]);


process.stdout.write(out_arr[index]);


process.stdin.on('data', (input)=>{


    //对输入进行保存
    in_arr[index] = input.toString().trim();

    index++;

    if(index>=out_arr.length){


        let info_str = JSON.stringify({

            appID:in_arr[0],
            appsecret:in_arr[1]

        }, null, 4);



        let file = __dirname+'/wxinfo.json';

        fs.writeFileSync(file, info_str);


        log('green','\n数据始化完成,生成文件  wxinfo.json');


        //使流动模式的流停止触发 data 事件
        return process.stdin.pause();

    }

    process.stdout.write(out_arr[index]);



})